#MP Moralization and Foreign Policy Attitudes Replication File: Study 2 analyses 
####Last updated: 3 June 2025

###Analyses carried out using R version 4.4.3 in RStudio version Version XXX on Lenovo ThinkPad X1 Carbon Gen 12 Intel Core Ultra 7 155U, 1700 Mhz, 12 running Windows 11 Enterprize

#### This file replicates results in the manuscript. Run "MP_study2_0.R" first for variable coding, functions, and packages!


#sample size
nrow(data) #3035


##Check survey progress among pruned responses
progtab <- table(data$Progress)
sum(progtab[1:19]) #46 participants completed between 10 and 97% of the survey; 2989 completes


# ### Figure 4: Average Effect of Cost Treatment on Policy Support --------

#Estimate the models
#Vaccine vignette
vax1 <- lm(suppvax1 ~ vaxtreat + aidfirst, data=data)
s.vax1 <- summary(vax1)

#Counter-terrorism vignette
terr1 <- lm(suppterr1 ~ terrtreat + aidfirst, data=data)
s.terr1 <- summary(terr1)

#Organize the ATEs
## Create a data frame with coefficients and standard errors
ates <- matrix(NA, nrow=2, ncol=3)
getSE <- function(mod, i){
  b <- mod$coefficients[i, 1]
  se <- mod$coefficients[i,2]
  return(c(b,b-1.96*se,b+1.96*se))
}

ates[1,] <- getSE(s.vax1, 2)
ates[2,] <- getSE(s.terr1, 2)

#Prepare the data frame for plotting:
names.coefs <- rbind("High Cost", "High Cost")
dvs.ates <- rbind("Vaccines", "Counter-terrorism")
df.ates <- data.frame(cbind(names.coefs, ates, dvs.ates))
colnames(df.ates) <- c("Treatment", "Effect", "Low", "High", "Issue")
df.ates$Effect <- as.numeric(as.character(df.ates$Effect))
df.ates$Low <- as.numeric(as.character(df.ates$Low))
df.ates$High <- as.numeric(as.character(df.ates$High))
df.ates$Treatment <- factor(df.ates$Treatment) 

##Create Figure 4:
dev.new(height=7,width=12)
p.ates.s2 <- ggplot(df.ates, aes(x=Effect, y=Issue)) +  
  geom_vline(xintercept = 0, colour="gray70", linewidth=1) + 
  geom_pointrangeh(data=df.ates, mapping=(aes(x=Effect, y=Issue, xmin=Low, xmax=High, linetype=factor(Issue), color=factor(Issue), size=I(1.2))), 
                   position = position_dodge2v(height = 0.75)) + 
  scale_shape_discrete(name="") + scale_colour_manual(values=c("black","grey60")) +
  ylab("") + xlab("Coefficient (95% Confidence Interval)") + ggtitle("Average Treatment Effect on Policy Support") +
  coord_cartesian(clip="off") +
  theme_bw() + theme(axis.text.y=element_text(color="black", size=16), axis.text.x=element_text(color="black", size=16), 
                     axis.title.y=element_text(color="black"),
                     axis.title.x=element_text(size=14), plot.title=element_text(color="black", size=14, hjust=0.5),
                     legend.text=element_text(size=14), 
                     legend.position="none") 
#######Figure 4 #############
p.ates.s2 


#Treatment effects referenced in text:

#High costs decreased support for global vaccine aid by 20 percentage points and support for counter-terrorism sanctions by 15 percentage points:
cbind(round(s.vax1$coefficients[2], digits=2)*100, round(s.vax1$coefficients[2,4], digits=3)) #-20 percentage points, p<0.01
cbind(round(s.terr1$coefficients[2], digits=2)*100, round(s.terr1$coefficients[2,4], digits=3)) #-15 percentage points, p<0.01



# Pre-treatment moral conviction correlates with policy support -----------
vax2 <- lm(suppvax1 ~ vaxtreat*pmc_health1 + aidfirst, data=data)
terr2 <- lm(suppterr1 ~ terrtreat*pmc_counter1 +  aidfirst, data=data)

s.vax2 <- summary(vax2)
s.terr2 <- summary(terr2)

cbind(round(s.vax2$coefficients[3], digits=2), round(s.vax2$coefficients[3,4], digits=3)) #b=0.46, p<0.01
cbind(round(s.terr2$coefficients[3], digits=2), round(s.terr2$coefficients[3,4], digits=3)) #b=0.31, p<0.01

###See MP_study2_2.R for full models referenced in footnote 23!

# ### Figure 5: Moral Conviction, Costs, and Policy Support (and surrounding text)---------------

#Plot the interactions; control for experiment order
set.seed(3753)
#Panel a: 
int.vax.kern <- interflex("kernel", data=data, Y="suppvax1", D="vaxtreat", X="pmc_health1", base="lowaid", Z="aidfirst", na.rm=TRUE, nboots=1000,
                          Ylabel="", Dlabel="High Cost", Xlabel="Moral Conviction", theme.bw = TRUE, ylab="Marginal Effect of High Cost",
                          xlab="Moral Conviction", main = "a) Support for Vaccine Aid", cex.main=1.2, cex.lab=1.1)


set.seed(3753)
#Panel b: 
int.terr.kern <- interflex("kernel", data=data, Y="suppterr1", D="terrtreat", base="lowterr", X="pmc_counter1", Z="aidfirst", na.rm=TRUE,
                           nboots=1000,Ylabel="", Dlabel="High Cost", Xlabel="Moral Conviction", theme.bw = TRUE, ylab="Marginal Effect of High Cost",
                           xlab="Moral Conviction", main = "b) Support for Counter-terrorism", cex.main=1.2, cex.lab=1.1)



#Produce Figure 5: ###########
dev.new(height=7,width=12)
s2ints <- grid.arrange(int.vax.kern$figure, int.terr.kern$figure, ncol=2)
s2ints


#Linear interaction statistics referenced in text:
cbind(round(s.vax2$coefficients[5], digits=2), round(s.vax2$coefficients[5,4], digits=3)) #b=0.08, p<0.05
cbind(round(s.terr2$coefficients[5], digits=3), round(s.terr2$coefficients[5,4], digits=3)) #b=0.004, p=0.917

#Other statistics referenced in text:
#Correlation between pre-treatment moral conviction and post-treatment care about counter-terrorism:
terr.c2 <- lm(care_terr1 ~ terrtreat*pmc_counter1 + aidfirst, data=data)
s.terr.c2 <- summary(terr.c2)

cbind(round(s.terr.c2$coefficients[3], digits=2), round(s.terr.c2$coefficients[3,4], digits=3)) #b=0.4, p<0.01

#Correlation between pre-treatment moral conviction and post-treatment moral conviction about counter-terrorism: 
terr.f2 <- lm(fund_terror1 ~ terrtreat*pmc_counter1 + aidfirst, data=data)
s.terr.f2 <- summary(terr.f2)

cbind(round(s.terr.f2$coefficients[3], digits=2), round(s.terr.f2$coefficients[3,4], digits=3)) #b=0.61, p<0.01

###See MP_study2_2.R for full models referenced in footnote 25!

            
# ### Figure 6: Moral Conviction and Support for Active Participation --------

#First, estimate the models: 
vaxa2 <- lm(actions_vax ~ vaxtreat*pmc_health1 + aidfirst, data=data)
s.vax.a2 <- summary(vaxa2)

terra2 <- lm(actions_terr ~ terrtreat*pmc_counter1 + aidfirst, data=data)
s.terr.a2 <- summary(terra2)

#Prepare the data for plotting: 
## Create a data frame with coefficients and standard errors
acts <- matrix(NA, nrow=6, ncol=3)
getSE <- function(mod, i){
  b <- mod$coefficients[i, 1]
  se <- mod$coefficients[i,2]
  return(c(b,b-1.96*se,b+1.96*se))
}

acts[1,] <- getSE(s.vax.a2, 2)
acts[2,] <- getSE(s.vax.a2, 3)
acts[3,] <- getSE(s.vax.a2, 5)
acts[4,] <- getSE(s.terr.a2, 2)
acts[5,] <- getSE(s.terr.a2, 3)
acts[6,] <- getSE(s.terr.a2, 5)

#Label and organize the data frame: 
names.coefs.acts <- rbind("High Cost", "Conviction", "Cost x \n Conviction","High Cost","Conviction", "Cost x \n Conviction")
dvs.acts <- rbind("Vaccines", "Vaccines", "Vaccines", "Counter-terrorism","Counter-terrorism","Counter-terrorism")
df.acts <- data.frame(cbind(names.coefs.acts, acts, dvs.acts))
colnames(df.acts) <- c("IV", "Coefficient", "Low", "High", "Issue")
df.acts$Effect <- as.numeric(as.character(df.acts$Coefficient))
df.acts$Low <- as.numeric(as.character(df.acts$Low))
df.acts$High <- as.numeric(as.character(df.acts$High))
df.acts$IV <- factor(df.acts$IV, levels=c("High Cost", "Conviction", "Cost x \n Conviction"))

# Create Figure 6 #######
dev.new(height=7,width=12)
p.acts <- ggplot(df.acts, aes(x=Coefficient, y=IV)) +  
  geom_vline(xintercept = 0, colour="gray70", linewidth=1) + 
  geom_pointrangeh(data=df.acts, mapping=(aes(x=Effect, y=IV, xmin=Low, xmax=High, color=factor(Issue), size=I(1.2))), 
                   position = position_dodge2v(height = 0.75)) + 
  scale_shape_discrete(name="") + scale_colour_manual(name="", values=c("black","grey60")) +
  scale_y_discrete(limits = rev(levels(df.acts$IV))) + 
  ylab("") + xlab("Coefficient (95% Confidence Interval)") + ggtitle("Endorse Active Measures to Promote Policy Views") +
  coord_cartesian(clip="off") +
  theme_bw() + theme(axis.text.y=element_text(color="black", size=16), axis.text.x=element_text(color="black", size=16), 
                     axis.title.y=element_text(color="black"),
                     axis.title.x=element_text(size=14), plot.title=element_text(color="black", size=14, hjust=0.5),
                     legend.text=element_text(size=14), 
                     legend.position="bottom") 
# Figure 6: ############
p.acts

#Statistics referenced in text:
#Without accounting for moral conviction, high costs decrease number of actions: 
vaxa1 <- lm(actions_vax ~ vaxtreat + aidfirst, data=data)
terra1 <- lm(actions_terr ~ terrtreat + aidfirst, data=data)
s.vaxa1 <- summary(vaxa1)
s.terra1 <- summary(terra1)

##Effect of costs
cbind(round(s.vaxa1$coefficients[2], digits=2), round(s.vaxa1$coefficients[2,4], digits=3)) #b=-0.14, p<0.01
cbind(round(s.terra1$coefficients[2], digits=2), round(s.terra1$coefficients[2,4], digits=3)) #b=-0.15, p<0.01

#Significant negative interaction between moral conviction and treatment in vaccine aid; 
cbind(round(s.vax.a2$coefficients[5], digits=2), round(s.vax.a2$coefficients[5,4], digits=3)) #b=-0.27, p<0.05
# the interaction coefficient is negative and not significant for the counter-terrorism vignette:
cbind(round(s.terr.a2$coefficients[5], digits=2), round(s.terr.a2$coefficients[5,4], digits=3)) #b=-0.17, p=0.183



# Means by moral conviction tercile: --------------------------------------

#Vaccines vignette: 

#Calculate terciles: 
q.mc.vax <- quantile(data$pmc_health1, c(0.33, 0.5, 0.66), na.rm=TRUE)
q.mc.vax

#Create subsets:
df.vlo <- subset(data, data$pmc_health1<q.mc.vax[1] & !is.na(data$vaxtreat))
df.vmed <- subset(data, data$pmc_health1>=q.mc.vax[1] & data$pmc_health1<q.mc.vax[3] & !is.na(data$vaxtreat))
df.vhi <- subset(data, data$pmc_health1>=q.mc.vax[3] & !is.na(data$vaxtreat))

#Calculate summary statistics:
means.act.vaxlo <- summarySE(df.vlo, measurevar="actions_vax", groupvars="vaxtreat", na.rm=TRUE)
means.act.vaxmed <- summarySE(df.vmed, measurevar="actions_vax", groupvars="vaxtreat", na.rm=TRUE)
means.act.vaxhi <- summarySE(df.vhi, measurevar="actions_vax", groupvars="vaxtreat", na.rm=TRUE)

#Combine:
dvaxmc <- rbind(means.act.vaxlo, means.act.vaxmed, means.act.vaxhi)

#Low conviction subgroup means::
cbind("low cost", round(dvaxmc[1,3], digits=2), "high cost", round(dvaxmc[2,3], digits=2)) #means = 0.45 (low), 0.47 (high)
#T-test for difference of means in low conviction group
t.vax.lo <- t.test(actions_vax ~ vaxtreat, data=df.vlo) # t=-0.36021, p=0.7188
cbind(round(t.vax.lo$statistic, digits=2), round(t.vax.lo$p.value, digits=3)) # t=-0.36, p=0.72


#Counter-terrorism vignette: 
q.mc.terr <- quantile(data$pmc_counter1, c(0.33, 0.5, 0.66), na.rm=TRUE)
q.mc.terr

df.tlo <- subset(data, data$pmc_counter1<q.mc.terr[1] & !is.na(data$terrtreat))
df.tmed <- subset(data, data$pmc_counter1>=q.mc.terr[1] & data$pmc_counter1<q.mc.terr[3]& !is.na(data$terrtreat))
df.thi <- subset(data, data$pmc_counter1>=q.mc.terr[3]& !is.na(data$terrtreat))

means.act.terrlo <- summarySE(df.tlo, measurevar="actions_terr", groupvars="terrtreat", na.rm=TRUE)
means.act.terrmed <- summarySE(df.tmed, measurevar="actions_terr", groupvars="terrtreat", na.rm=TRUE)
means.act.terrhi <- summarySE(df.thi, measurevar="actions_terr", groupvars="terrtreat", na.rm=TRUE)

#Combine:
dterrmc <- rbind(means.act.terrlo, means.act.terrmed, means.act.terrhi)

#Low conviction subgroup means::
cbind("low cost", round(dterrmc[1,3], digits=2), "high cost", round(dterrmc[2,3], digits=2)) #means = 0.42 (low), 0.31 (high)
#T-test for difference of means in low conviction group
t.terr.lo <- t.test(actions_terr ~ terrtreat, data=df.tlo) 
cbind(round(t.terr.lo$statistic, digits=2), round(t.terr.lo$p.value, digits=3)) # t=1.98, p=0.049


# ### Figure 7: Participatory Engagement means by subgroup ----------------

#Vaccine vignette:
#Create subsets for low, moderate, and high moral conviction among vaccine aid supporters: 
df.vsupplo <- subset(dat.vsupp, dat.vsupp$pmc_health1<q.mc.vax[1] & !is.na(dat.vsupp$vaxtreat))
df.vsuppmed <- subset(dat.vsupp, dat.vsupp$pmc_health1>=q.mc.vax[1] & dat.vsupp$pmc_health1<q.mc.vax[3] & !is.na(dat.vsupp$vaxtreat))
df.vsupphi <- subset(dat.vsupp, dat.vsupp$pmc_health1>=q.mc.vax[3] & !is.na(dat.vsupp$vaxtreat))

#Calculate summary statistics:
means.act.vaxlo.supp <- summarySE(df.vsupplo, measurevar="actions_vax", groupvars="vaxtreat", na.rm=TRUE)
means.act.vaxmed.supp <- summarySE(df.vsuppmed, measurevar="actions_vax", groupvars="vaxtreat", na.rm=TRUE)
means.act.vaxhi.supp <- summarySE(df.vsupphi, measurevar="actions_vax", groupvars="vaxtreat", na.rm=TRUE)

#Create subsets for low, moderate, and high moral conviction among vaccine aid non-supporters: 
df.vopplo <- subset(dat.vopp, dat.vopp$pmc_health1<q.mc.vax[1] & !is.na(dat.vopp$vaxtreat))
df.voppmed <- subset(dat.vopp, dat.vopp$pmc_health1>=q.mc.vax[1] & dat.vopp$pmc_health1<q.mc.vax[3] & !is.na(dat.vopp$vaxtreat))
df.vopphi <- subset(dat.vopp, dat.vopp$pmc_health1>=q.mc.vax[3] & !is.na(dat.vopp$vaxtreat))

#Calculate summary statistics:
means.act.vaxlo.op <- summarySE(df.vopplo, measurevar="actions_vax", groupvars="vaxtreat", na.rm=TRUE)
means.act.vaxmed.op <- summarySE(df.voppmed, measurevar="actions_vax", groupvars="vaxtreat", na.rm=TRUE)
means.act.vaxhi.op <- summarySE(df.vopphi, measurevar="actions_vax", groupvars="vaxtreat", na.rm=TRUE)


#Counter-terrorism vignette:
#Create subsets for low, moderate, and high moral conviction among counter-terrorism supporters: 
dat.tsupplo <- subset(dat.tsupp, dat.tsupp$pmc_counter1<q.mc.terr[1] & !is.na(dat.tsupp$terrtreat))
dat.tsuppmed <- subset(dat.tsupp, dat.tsupp$pmc_counter1>=q.mc.terr[1] & dat.tsupp$pmc_counter1<q.mc.terr[3] & !is.na(dat.tsupp$terrtreat))
dat.tsupphi <- subset(dat.tsupp, dat.tsupp$pmc_counter1>=q.mc.terr[3] & !is.na(dat.tsupp$terrtreat))

#Calculate summary statistics:
means.act.terlo.supp <- summarySE(dat.tsupplo, measurevar="actions_terr", groupvars="terrtreat", na.rm=TRUE)
means.act.termed.supp <- summarySE(dat.tsuppmed, measurevar="actions_terr", groupvars="terrtreat", na.rm=TRUE)
means.act.terhi.supp <- summarySE(dat.tsupphi, measurevar="actions_terr", groupvars="terrtreat", na.rm=TRUE)

#Create subsets for low, moderate, and high moral conviction among counter-terrorism non-supporters:
df.topplo <- subset(dat.topp, dat.topp$pmc_counter1<q.mc.terr[1] & !is.na(dat.topp$terrtreat))
df.toppmed <- subset(dat.topp, dat.topp$pmc_counter1>=q.mc.terr[1] & dat.topp$pmc_counter1<q.mc.terr[3] & !is.na(dat.topp$terrtreat))
df.topphi <- subset(dat.topp, dat.topp$pmc_counter1>=q.mc.terr[3] & !is.na(dat.topp$terrtreat))

means.act.terlo.op <- summarySE(df.topplo, measurevar="actions_terr", groupvars="terrtreat", na.rm=TRUE)
means.act.termed.op <- summarySE(df.toppmed, measurevar="actions_terr", groupvars="terrtreat", na.rm=TRUE)
means.act.terhi.op <- summarySE(df.topphi, measurevar="actions_terr", groupvars="terrtreat", na.rm=TRUE)


#Organize the Data for Plotting:

#Panel A: Vaccine supporter subgroup
vaxmeanssupp <- rbind(means.act.vaxlo.supp, means.act.vaxmed.supp, means.act.vaxhi.supp)
vaxmeanssupp$Treat <- c("Low Cost", "High Cost","Low Cost", "High Cost","Low Cost", "High Cost")
vaxmeanssupp$group <- c("Low Conviction", "Low Conviction", "Mid Conviction", "Mid Conviction", "High Conviction", "High Conviction")
vaxmeanssupp$group <- factor(vaxmeanssupp$group, levels = c("Low Conviction", "Mid Conviction", "High Conviction"))

#Panel B: Vaccine Non-supporter subgroup
vaxmeansop <- rbind(means.act.vaxlo.op, means.act.vaxmed.op, means.act.vaxhi.op)
vaxmeansop$Treat <- c("Low Cost", "High Cost","Low Cost", "High Cost","Low Cost", "High Cost")
vaxmeansop$group <- c("Low Conviction", "Low Conviction", "Mid Conviction", "Mid Conviction", "High Conviction", "High Conviction")
vaxmeansop$group <- factor(vaxmeansop$group, levels = c("Low Conviction", "Mid Conviction", "High Conviction"))


#Panel c: Counter-terrorism supporter subgroup
termeanssupp <- rbind(means.act.terlo.supp, means.act.termed.supp, means.act.terhi.supp)
termeanssupp$Treat <- c("Low Cost", "High Cost","Low Cost", "High Cost","Low Cost", "High Cost")
termeanssupp$group <- c("Low Conviction", "Low Conviction", "Mid Conviction", "Mid Conviction", "High Conviction", "High Conviction")
termeanssupp$group <- factor(termeanssupp$group, levels = c("Low Conviction", "Mid Conviction", "High Conviction"))

#Panel D: Counter-terrorism non-supporter subgroup
termeansop <- rbind(means.act.terlo.op, means.act.termed.op, means.act.terhi.op)
termeansop$Treat <- c("Low Cost", "High Cost","Low Cost", "High Cost","Low Cost", "High Cost")
termeansop$group <- c("Low Conviction", "Low Conviction", "Mid Conviction", "Mid Conviction", "High Conviction", "High Conviction")
termeansop$group <- factor(termeansop$group, levels = c("Low Conviction", "Mid Conviction", "High Conviction"))


#Create Panel A
p.acts.supp <- ggplot(vaxmeanssupp, aes(x=actions_vax)) + 
  geom_vline(aes(xintercept=mean(data$actions_vax, na.rm=TRUE)), colour="gray88", linetype="dashed") +
  geom_pointrangeh(data=vaxmeanssupp, mapping=(aes(x=actions_vax, y=group, xmin=actions_vax-ci, xmax=actions_vax+ci, linetype=factor(Treat), shape=factor(Treat), colour=factor(Treat))), 
                   position = position_dodge2v(height = 0.75), size=I(1.1)) +
  scale_y_discrete(limits = levels(vaxmeanssupp$group)) + 
  scale_linetype_discrete(name="", guide="none") +
  scale_shape_discrete(name="") +
  scale_x_continuous(limits=c(0.16, 1.95)) +
  scale_colour_manual(name="", values=c( "gray60", "gray0")) +
  ylab("") + xlab("Number of Participations for Vaccines") + ggtitle("a) Supporter Subgroup") +
  coord_cartesian(clip="off") +
  theme_bw() + theme(axis.text.y=element_text(color="black", size=13), 
                     axis.text.x=element_text(color="black"), 
                     axis.title.y=element_text(color="black", size=14),
                     axis.title.x=element_text(size=14), plot.title=element_text(color="black", size=14, hjust=0.5),
                     legend.text=element_text(size=14), 
                     legend.position="bottom", plot.margin = unit(c(.5,.5,.5,1.5), "cm"))


#Create Panel B:
p.acts.op <- ggplot(vaxmeansop, aes(x=actions_vax)) + 
  geom_vline(aes(xintercept=mean(data$actions_vax, na.rm=TRUE)), colour="gray88", linetype="dashed") +
  geom_pointrangeh(data=vaxmeansop, mapping=(aes(x=actions_vax, y=group, xmin=actions_vax-ci, xmax=actions_vax+ci, linetype=factor(Treat), shape=factor(Treat), colour=factor(Treat))), 
                   position = position_dodge2v(height = 0.75), size=I(1.1)) +
  scale_y_discrete(limits = levels(vaxmeansop$group)) + 
  scale_linetype_discrete(name="", guide="none") +
  scale_shape_discrete(name="") +
  scale_x_continuous(limits=c(0.16, 1.95)) +
  scale_colour_manual(name="", values=c( "gray60", "gray0")) +
  ylab("") + xlab("Number of Participations for Vaccines") + ggtitle("b) Non-Supporter Subgroup") +
  coord_cartesian(clip="off") +
  theme_bw() + theme(axis.text.y=element_text(color="black", size=13), 
                     axis.text.x=element_text(color="black"), 
                     axis.title.y=element_text(color="black", size=14),
                     axis.title.x=element_text(size=14), plot.title=element_text(color="black", size=14, hjust=0.5),
                     legend.text=element_text(size=14), 
                     legend.position="bottom", plot.margin = unit(c(.5,.5,.5,1.5), "cm"))


#Create Panel C: 
p.acts.tersupp <- ggplot(termeanssupp, aes(x=actions_terr)) + 
  geom_vline(aes(xintercept=mean(data$actions_terr, na.rm=TRUE)), colour="gray88", linetype="dashed") +
  geom_pointrangeh(data=termeanssupp, mapping=(aes(x=actions_terr, y=group, xmin=actions_terr-ci, xmax=actions_terr+ci, linetype=factor(Treat), shape=factor(Treat), colour=factor(Treat))), 
                   position = position_dodge2v(height = 0.75), size=I(1.1)) +
  scale_y_discrete(limits = levels(termeanssupp$group)) + 
  scale_linetype_discrete(name="", guide="none") +
  scale_shape_discrete(name="") +
  scale_x_continuous(limits=c(0.16, 1.95)) +
  scale_colour_manual(name="", values=c( "gray60", "gray0")) +
  ylab("") + xlab("Number of Participations for Counter-Terrorism") + ggtitle("c) Supporter Subgroup") +
  coord_cartesian(clip="off") +
  theme_bw() + theme(axis.text.y=element_text(color="black", size=13), 
                     axis.text.x=element_text(color="black"), 
                     axis.title.y=element_text(color="black", size=14),
                     axis.title.x=element_text(size=14), plot.title=element_text(color="black", size=14, hjust=0.5),
                     legend.text=element_text(size=14), 
                     legend.position="bottom", plot.margin = unit(c(.5,.5,.5,1.5), "cm"))

#Create Panel D: 
p.acts.terop <- ggplot(termeansop, aes(x=actions_terr)) + 
  geom_vline(aes(xintercept=mean(data$actions_terr, na.rm=TRUE)), colour="gray88", linetype="dashed") +
  geom_pointrangeh(data=termeansop, mapping=(aes(x=actions_terr, y=group, xmin=actions_terr-ci, xmax=actions_terr+ci, linetype=factor(Treat), shape=factor(Treat), colour=factor(Treat))), 
                   position = position_dodge2v(height = 0.75), size=I(1.1)) +
  scale_y_discrete(limits = levels(termeansop$group)) + 
  scale_linetype_discrete(name="", guide="none") +
  scale_shape_discrete(name="") +
  scale_x_continuous(limits=c(0.16, 1.95)) +
  scale_colour_manual(name="", values=c( "gray60", "gray0")) +
  ylab("") + xlab("Number of Participations for Counter-Terrorism") + ggtitle("d) Non-Supporter Subgroup") +
  coord_cartesian(clip="off") +
  theme_bw() + theme(axis.text.y=element_text(color="black", size=13), 
                     axis.text.x=element_text(color="black"), 
                     axis.title.y=element_text(color="black", size=14),
                     axis.title.x=element_text(size=14), plot.title=element_text(color="black", size=14, hjust=0.5),
                     legend.text=element_text(size=14), 
                     legend.position="bottom", plot.margin = unit(c(.5,.5,.5,1.5), "cm"))


### Figure 7: #####
dev.new(height=7,width=12)
grid.arrange(p.acts.supp, p.acts.op, p.acts.tersupp, p.acts.terop, ncol=2 )



# Subgroup analyses  ------------------------------------------------------

#Estimate average treatment effect in each subgroup

#Vaccines:
mod.vsup.a1 <- lm(actions_vax ~ vaxtreat + aidfirst, data=dat.vsupp)
mod.vopp.a1 <- lm(actions_vax ~ vaxtreat + aidfirst, data=dat.vopp)
s.mod.vsupa1 <- summary(mod.vsup.a1)
s.mod.voppa1 <- summary(mod.vopp.a1)


#Counter-terrorism:
mod.tsup.a1 <- lm(actions_terr ~ terrtreat + aidfirst, data=dat.tsupp)
mod.topp.a1 <- lm(actions_terr ~ terrtreat + aidfirst, data=dat.topp)
s.mod.tsupa1 <- summary(mod.tsup.a1)
s.mod.toppa1 <- summary(mod.topp.a1)


#Coefficients referenced in text:
#High costs decreases participatory actions among supporters, increases among non-supporters in vaccine vignette: 
cbind(round(s.mod.vsupa1$coefficients[2], digits=2), round(s.mod.vsupa1$coefficients[2,4], digits=3)) # b=-0.26, p<0.01
cbind(round(s.mod.voppa1$coefficients[2], digits=2), round(s.mod.voppa1$coefficients[2,4], digits=3)) # b=0.19, p<0.05

#similar negative effect among supporters, but not non-supporters, for counter-terrorism:
cbind(round(s.mod.tsupa1$coefficients[2], digits=2), round(s.mod.tsupa1$coefficients[2,4], digits=3)) # b=-0.18, p<0.01
cbind(round(s.mod.toppa1$coefficients[2], digits=2), round(s.mod.toppa1$coefficients[2,4], digits=3)) # b=-0.08, p=0.241

#Interactions:
mod.vsup.a2 <- lm(actions_vax ~ vaxtreat*pmc_health1 + aidfirst, data=dat.vsupp)
mod.vopp.a2 <- lm(actions_vax ~ vaxtreat*pmc_health1 + aidfirst, data=dat.vopp)
s.mod.vsupa2 <- summary(mod.vsup.a2)
s.mod.voppa2 <- summary(mod.vopp.a2)

mod.tsup.a2 <- lm(actions_terr ~ terrtreat*pmc_counter1 + aidfirst, data=dat.tsupp)
mod.topp.a2 <- lm(actions_terr ~ terrtreat*pmc_counter1 + aidfirst, data=dat.topp)
s.mod.tsupa2 <- summary(mod.tsup.a2)
s.mod.toppa2 <- summary(mod.topp.a2)


#Coefficients referenced in text
#no significant itneractions between moral conviction and costs in the subgroup analyses
cbind(round(s.mod.vsupa2$coefficients[5], digits=2), round(s.mod.vsupa2$coefficients[5,4], digits=3)) # b=-0.14, p=0.45; negative sign among supporters
cbind(round(s.mod.voppa2$coefficients[5], digits=2), round(s.mod.voppa2$coefficients[5,4], digits=3)) # b=0.22, p=0.35; positive sign among non-supporters

#small subset of high-conviction opponents:
nrow(df.vopphi) #n=95

#Similarly non-significant, oppositely signed interaction coefficients in the counter-terrorism scenario: 
cbind(round(s.mod.tsupa2$coefficients[5], digits=2), round(s.mod.tsupa2$coefficients[5,4], digits=3)) # b=-0.18, p=0.286; negative sign among supporters
cbind(round(s.mod.toppa2$coefficients[5], digits=2), round(s.mod.toppa2$coefficients[5,4], digits=3)) # b=0.08, p=0.724; positive sign among non-supporters


